alpha <- c(2, 4)
sigmasq.n <- c(.8, 1)
seq(11:20)
c(11:20)
c(.8,1)
c(11:20)
ls()
setwd("~/Dropbox/Perception_Inequality_wHannah/Survey Files/All SAS")
require("SASxport")
survey <- read.xport("harris_p3849_sas.export")
class(survey)
setwd("~/Dropbox/Perception_Inequality_wHannah/Survey Files/Harris 1969 American Foreign Policy Survey, study no. 1970")
require("SASxport")
survey <- read.xport("harris_s1970_sas.export")
View(survey)
View(survey)
survey$pid <- NA
survey$study <- 1970
c(1:nrow(survey))
survey$pid <- c(1:nrow(survey))
survey$year <- 1969
survey$urban <- NA
survey$region <- NA
survey$hh <- NA
summary(survey$Q17.A)
survey$inequality <- survey$Q17.A
survey$inequality.variable <- 1
summary(survey$F3.1)
summary(survey$F3.2)
summary(survey$F3.3) ## no union member in family
survey$union.self <- survey$F3.1
survey$union.other <- survey$F3.2
summary(survey$F2A)
survey$employed <- survey$F2A
summary(survey$F2B)
survey$occupation <- survey$F2B
survey$hhsize <- NA
summary(survey$F6)
survey$educ <- survey$F6
survey$educ <- as.character(survey$educ)
levels(survey$F6)[1]
levels(survey$F6)[2]
survey$educ[survey$educ == levels(survey$F6)[1] | survey$educ == levels(survey$F6)[2]]
?recode
require("dplyr")
?recode
recode(survey$educ, `8th grade or less` = "Less than high school",
`Some high school` = "Less than high school")
levels(survey$educ)
summary(survey$educ)
survey$educ <- survey$F6
recode(survey$educ, `8th grade or less` = "Less than high school",
`Some high school` = "Less than high school")
survey$educ <- survey$F6
summary(survey$educ)
recode(survey$educ, `8th grade or less` = "Less than high school",
`Some high school` = "Less than high school")
summary(survey$educ)
survey$educ <- survey$F6
summary(survey$educ)
survey$educ <- recode(survey$educ, `8th grade or less` = "Less than high school",
`Some high school` = "Less than high school")
summary(survey$educ)
survey$educ <- survey$F6
summary(survey$educ)
survey$educ <- recode(survey$educ, `8th grade or less` = "Less than high school",
`Some high school` = "Less than high school",
`2-yr cllg grdt (cmmnty cllg, tc )` = "Some college",
`4-year college graduate` = "College graduate")
summary(survey$educ)
summary(survey$F9)
survey$income <- survey$F9
summary(survey$F8)
summary(survey$F8.1)
summary(survey$F8.2)
sum(!is.na(survey$F8.1) & !is.na(survey$F8.2))
survey[!is.na(survey$F8.1) & !is.na(survey$F8.2),]
survey$S1[!is.na(survey$F8.1) & !is.na(survey$F8.2)]
survey[!is.na(survey$F8.1) & !is.na(survey$F8.2), c("S1", "F8.1", "F8.2")]
?ifelse
survey$age <- ifelse(is.na(survey$F8.1), survey$F8.2, survey$F8.1))
survey$age <- ifelse(is.na(survey$F8.1), survey$F8.2, survey$F8.1)
summary(survey$age)
summary(survey$F8.1)
survey$age
survey$age <- ifelse(is.na(survey$F8.1), as.character(survey$F8.2), as.character(survey$F8.1))
summary(survey$F8.1)
survey$age <- factor(survey$age)
summary(survey$age)
summary(survey$F8.2)
summary(survey$F10)
survey$race <- survey$F10
survey$party <- NA
survey$ideology <- NA
summary(survey$S1)
survey$sex <- survey$S1
summary(survey$F7)
survey$religion <- survey$F7
### put together data set
survey1970 <- survey[,c("pid", "study", "year", "urban", "region", "hh",
"inequality", "inequality.variable", "union.self.", "union.other",
"employed", "occupation", "hhsize", "educ", "income",
"age", "race", "party", "ideology", "sex", "religion")]
survey1970 <- survey[,c("pid", "study", "year", "urban", "region", "hh",
"inequality", "inequality.variable", "union.self", "union.other",
"employed", "occupation", "hhsize", "educ", "income",
"age", "race", "party", "ideology", "sex", "religion")]
saveRDS(survey1970, file = "survey_1970")
survey_1970 <- survey[,c("pid", "study", "year", "urban", "region", "hh",
"inequality", "inequality.variable", "union.self", "union.other",
"employed", "occupation", "hhsize", "educ", "income",
"age", "race", "party", "ideology", "sex", "religion")]
## save dataset in folder (i.e. working directory must be set to folder)
saveRDS(survey_1970, file = "survey_1970")
summary(survey$inequality)
summary(survey$F3.1)
?data.frame
data1 <- data.frame(y = factor(c("Yes", "No", "okay", "No")), x = c("Yes", "No", "okay", "No"))
data1
data2 <- data.frame(y = factor(c("since", "because", "since", "alright")), x = c("since", "because", "since", "alright"))
data2
data3 <- rbind(data1, data2)
data3
class(data3$y)
summary(data3$y)
summary(data3$x)
class(data3$x)
levels(data3$x)
data1 <- data.frame(y = factor(c("Yes", "No", "okay", "No"), ordered = TRUE), x = c("Yes", "No", "okay", "No"))
data2 <- data.frame(y = factor(c("since", "because", "since", "alright"), ordered = TRUE), x = c("since", "because", "since", "alright"))
data3 <- rbind(data1, data2)
data3
levels(data3$x)
levels(data1$x)
ordered(data1$x)
is.ordered(data1$x)
data1 <- data.frame(y = factor(c("Yes", "No", "okay", "No"), ordered = TRUE), x = c("Yes", "No", "okay", "No"))
is.ordered(data1$x)
data1$y <- ordered(data1$y)
data2$y <- ordered(data2$y)
data3 <- rbind(data1, data2)
data3
is.ordered(data1$x)
ordered(data1$y)
data1 <- data.frame(y = factor(c("Yes", "No", "okay", "No"), ordered = TRUE), x = c("Yes", "No", "okay", "No"))
data1$y <- ordered(data1$y)
is.ordered(data1$y)
data3
is.ordered(data3$y)
levels(data3$y)
summary(survey$S1)
class(survey$pid)
class(survey$pid)
class(survey$pid)
class(survey$study)
class(survey$year)
class(survey$urban)
class(survey$inequality)
summary(survey$inequality)
is.ordered(survey$inequality)
class(survey$inequality.variable)
class(survey$union.self)
class(survey$union.other)
class(survey$employed)
summary(survey$employed)
class(survey$employed)
class(survey$occupation)
class(survey$occupation)
class(survey$educ)
is.ordered(survey$educ)
levels (survey$educ)
summary(survey$educ)
survey$educ <- ordered(survey$educ,
levels = c("Less than high school", "High school graduate",
"Some college", "College graduate",
"Post graduate"))
summary(survey$educ)
is.ordered(survey$educ)
class(survey$educ)
summary(survey$income)
class(sursvey$income)
class(survey$income)
class(survey$age)
summary(survey$age)
class(survey$race)
survey$gender <- survey$S1
class(survey$gender)
class(survey$religion)
setwd("~/Dropbox/Perception_Inequality_wHannah/Survey Files/Harris 1969 American Foreign Policy Survey, study no. 1970")
## packages
require("SASxport")
require("dplyr")
## download data
survey <- read.xport("harris_s1970_sas.export")
## pid
survey$pid <- c(1:nrow(survey))
class(survey$pid)
## study number
survey$study <- 1970
class(survey$study)
## year
survey$year <- 1969
class(survey$year)
## geographpic data
survey$urban <- NA
class(survey$urban)
## region
survey$region <- NA
## respondent name
survey$hh <- NA
## inequality increasing
summary(survey$Q17.A)
survey$inequality <- survey$Q17.A
class(survey$inequality)
is.ordered(survey$inequality)
## inequality variable version
survey$inequality.variable <- 1
class(survey$inequality.variable)
## union
summary(survey$F3.1) ## are you a union member
summary(survey$F3.2) ## is any member of family a union member
survey$union.self <- survey$F3.1
survey$union.other <- survey$F3.2
class(survey$union.self)
class(survey$union.other)
## Are you employed? what kind of employment?
survey$employed <- survey$F2A
class(survey$employed)
## Occupation
summary(survey$F2B)
survey$occupation <- survey$F2B
class(survey$occupation)
## household size
survey$hhsize <- NA
class(survey$occupation)
## Education
summary(survey$F6)
survey$educ <- survey$F6
survey$educ <- recode(survey$educ, `8th grade or less` = "Less than high school",
`Some high school` = "Less than high school",
`2-yr cllg grdt (cmmnty cllg, tc )` = "Some college",
`4-year college graduate` = "College graduate")
levels (survey$educ)
summary(survey$educ)
survey$educ <- ordered(survey$educ,
levels = c("Less than high school", "High school graduate",
"Some college", "College graduate",
"Post graduate"))
class(survey$educ)
is.ordered(survey$educ)
## Income
summary(survey$F9)
survey$income <- survey$F9
summary(survey$income)
class(survey$income)
## Age
summary(survey$F8.1)
summary(survey$F8.2)
sum(!is.na(survey$F8.1) & !is.na(survey$F8.2))
survey[!is.na(survey$F8.1) & !is.na(survey$F8.2), c("S1", "F8.1", "F8.2")]
survey$age <- ifelse(is.na(survey$F8.1), as.character(survey$F8.2), as.character(survey$F8.1))
survey$age <- factor(survey$age)
class(survey$age)
summary(survey$age)
## race
summary(survey$F10)
survey$race <- survey$F10
class(survey$race)
## politics
survey$party <- NA
## ideology
survey$ideology <- NA
## gender
summary(survey$S1)
survey$gender <- survey$S1
class(survey$gender)
## religion
summary(survey$F7)
survey$religion <- survey$F7
class(survey$religion)
### put together data set
survey_1970 <- survey[,c("pid", "study", "year", "urban", "region", "hh",
"inequality", "inequality.variable", "union.self", "union.other",
"employed", "occupation", "hhsize", "educ", "income",
"age", "race", "party", "ideology", "gender", "religion")]
saveRDS(survey_1970, file = "survey_1970.rds")
survey <- readRDS("survey_1970.rds")
View(survey)
# Harris 1969 American Foreign Policy Survey, study no. 1970
setwd("~/Dropbox/Perception_Inequality_wHannah/Survey Files/Harris 1969 American Foreign Policy Survey, study no. 1970")
## packages
require("SASxport")
require("dplyr")
## download data
survey <- read.xport("harris_s1970_sas.export")
## pid
survey$pid <- c(1:nrow(survey))
class(survey$pid)
## study number
survey$study <- as.character(1970)
class(survey$study)
## year
survey$year <- 1969
class(survey$year)
## geographpic data
survey$urban <- NA
class(survey$urban)
## region
survey$region <- NA
## respondent name
survey$hh <- NA
## inequality increasing
summary(survey$Q17.A)
survey$inequality <- survey$Q17.A
class(survey$inequality)
is.ordered(survey$inequality)
## inequality variable version
survey$inequality.variable <- 1
class(survey$inequality.variable)
## union
summary(survey$F3.1) ## are you a union member
summary(survey$F3.2) ## is any member of family a union member
survey$union.self <- survey$F3.1
survey$union.other <- survey$F3.2
class(survey$union.self)
class(survey$union.other)
## Are you employed? what kind of employment?
survey$employed <- survey$F2A
class(survey$employed)
## Occupation
summary(survey$F2B)
survey$occupation <- survey$F2B
class(survey$occupation)
## household size
survey$hhsize <- NA
class(survey$hhsize)
## Education
summary(survey$F6)
survey$educ <- survey$F6
survey$educ <- recode(survey$educ, `8th grade or less` = "Less than high school",
`Some high school` = "Less than high school",
`2-yr cllg grdt (cmmnty cllg, tc )` = "Some college",
`4-year college graduate` = "College graduate")
levels (survey$educ)
summary(survey$educ)
survey$educ <- ordered(survey$educ,
levels = c("Less than high school", "High school graduate",
"Some college", "College graduate",
"Post graduate"))
class(survey$educ)
is.ordered(survey$educ)
## Income
summary(survey$F9)
survey$income <- survey$F9
summary(survey$income)
class(survey$income)
## Age
summary(survey$F8.1)
summary(survey$F8.2)
sum(!is.na(survey$F8.1) & !is.na(survey$F8.2))
survey[!is.na(survey$F8.1) & !is.na(survey$F8.2), c("S1", "F8.1", "F8.2")]
sum(is.na(survey$F8.1) & is.na(survey$F8.2))
survey$age <- ifelse(is.na(survey$F8.1), as.character(survey$F8.2), as.character(survey$F8.1))
survey$age <- factor(survey$age)
class(survey$age)
summary(survey$age)
## race
summary(survey$F10)
survey$race <- survey$F10
class(survey$race)
## politics
survey$party <- NA
## ideology
survey$ideology <- NA
## gender
summary(survey$S1)
require("dplyr")
survey$gender <- factor(dplyr::recode(survey$S1,
`MALE` = "Male",
`FEMALE` = "Female"))
class(survey$gender)
summary(survey$gender)
## religion
summary(survey$F7)
survey$religion <- survey$F7
class(survey$religion)
### put together data set
survey_1970 <- survey[,c("pid", "study", "year", "urban", "region", "hh",
"inequality", "inequality.variable", "union.self", "union.other",
"employed", "occupation", "hhsize", "educ", "income",
"age", "race", "party", "ideology", "gender", "religion")]
summary(survey_1970)
## save dataset in folder (i.e. working directory must be set to folder)
saveRDS(survey_1970, file = "survey_1970.rds")
